package com.guigui.erp.controller;

import com.guigu.erp.dto.StorageGatherDto;
import com.guigu.erp.pojo.StorageGather;
import com.guigu.erp.service.StorageGatherService;
import com.guigu.erp.utils.PageUtils;
import com.guigu.erp.vo.DesignFileVo;
import com.guigui.erp.utils.NumberUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author Lenovo
 */
@Controller
@RequestMapping("/design/storageGather")
public class StorageGatherController {
    @Autowired
    private NumberUtils numberUtils;

    @Autowired
    private StorageGatherService storageGatherService;

    /**
     * 处理制定安全库存配置单的确认按钮请求
     */
    @RequestMapping("/add")
    @ResponseBody
    public String addStorageGather(@RequestBody StorageGatherDto storageGatherDto){
        // 生成安全库存配置单编号
        String gatherId = numberUtils.getTypeNumber("401");
        storageGatherDto.setGatherId(gatherId);

        // 设置审核标志 S001-0 等待审核
        storageGatherDto.setCheckTag("S001-0");

        //设置库存标志 K002-1 已登记
        storageGatherDto.setStoreTag("K002-1");

        //调用业务层方法
        storageGatherService.makeStorageGather(storageGatherDto);
        return "correct";
    }

    /**
     * 库存安全配置单的复核查询
     */
    @RequestMapping("/storageGatherQuery")
    @ResponseBody
    public PageUtils<StorageGather> recheckPage(DesignFileVo vo, int pageNo, int pageSize) {
        PageUtils<StorageGather> recheckPage = this.storageGatherService.recheckPage(vo, pageNo, pageSize);
        return recheckPage;
    }

    /**
     * 根据入库id查询入库明细单信息
     */
    @RequestMapping("/storageGatherGetId")
    @ResponseBody
    public StorageGather storageGatherGetId(int id) {
        StorageGather storageGather = this.storageGatherService.getById(id);
        return storageGather;
    }

    /**
     * 库存安全配置单复核通过
     * @param
     * @return
     */
    @RequestMapping("storageGatherReviewPassed")
    @ResponseBody
    public String storageGatherReviewPassed(StorageGather storageGather) {
        storageGather.setCheckTag("S001-1");
        boolean flag = storageGatherService.updateById(storageGather);
        if (flag) {
            return "correct";
        }
        return "error";
    }

    /**
     * 库存安全配置单查询请求
     */
    @RequestMapping("/list")
    @ResponseBody
    public PageUtils<StorageGather> storageGatherList(DesignFileVo vo, int pageNo, int pageSize) {
        PageUtils<StorageGather> page = this.storageGatherService.GatherListPage(vo, pageNo, pageSize);
        return page;
    }

    /**
     * 库存安全配置单的复核查询
     */
    @RequestMapping("/storageGatherInQuery")
    @ResponseBody
    public PageUtils<StorageGather> storageGatherInList(DesignFileVo vo, int pageNo, int pageSize) {
        PageUtils<StorageGather> recheckPage = this.storageGatherService.GatherListPage2(vo, pageNo, pageSize);
        return recheckPage;
    }

    /**
     * 库存安全配置单的调度
     */
    @RequestMapping("/storageGatherQuery2")
    @ResponseBody
    public PageUtils<StorageGather> recheckPage2(DesignFileVo vo, int pageNo, int pageSize) {
        PageUtils<StorageGather> recheckPage = this.storageGatherService.recheckPage2(vo, pageNo, pageSize);
        return recheckPage;
    }

    /**
     * 通过父级id查询入库表的一列
     */
    @RequestMapping("/listGatherById")
    @ResponseBody
    public StorageGather listGatherById(String parentId){
        StorageGather pageUtils=storageGatherService.listGatherById(parentId);
        return pageUtils;
    }

    /**
     * 根据id修改K002-2: 已调度
     */
    @RequestMapping("/update")
    @ResponseBody
    public String Update(@RequestBody StorageGather storageGather){
        storageGather.setStoreTag("K002-2");
        boolean flag=storageGatherService.updateById(storageGather);
        if(flag){
            return "correct";
        }
        return "error";
    }
}
